<template>
  <view class="invoice_container">
    <view class="tips">
      本月可申请开发票次数：<text>{{ num }}</text>
    </view>
    <view class="item" @click="clickItem('invoicing')">
      <text>开发票</text>
      <img :src="staticUrl() + '/personalCenter/right.png'" class="right" />
    </view>
    <view class="item" @click="clickItem('record')">
      <text>开票记录</text>
      <img :src="staticUrl() + '/personalCenter/right.png'" class="right" />
    </view>
  </view>
</template>

<script>
import { getApplicableInvoiceNum } from '@/api/invoice'

export default {
  data () {
    return {
      num: 0
    }
  },
  onLoad () {
    getApplicableInvoiceNum().then(res => {
      this.num = res.data
    })
  },
  methods: {
    clickItem (item) {
      if (item === 'invoicing') {
        if (!this.num) {
          uni.showToast({ icon: 'none', title: '本月次数已用尽', mask: true })
          return
        }
      }
      uni.navigateTo({ url: '/subpackage/invoice/' + item })
    }
  }
}
</script>

<style lang="scss" scoped>
.invoice_container {
  height: 100vh;
  background: #f9f9f9;
  overflow: hidden;

  .tips {
    width: 750rpx;
    height: 69rpx;
    background: #f1e9c3;
    font-size: 25rpx;
    font-weight: 400;
    color: #424040;
    line-height: 69rpx;
    text-align: center;
    margin-top: 20.83rpx;

    text {
      font-size: 25rpx;
      font-weight: 400;
      color: #ec2319;
    }
  }

  .item {
    width: 750rpx;
    height: 108rpx;
    background: #ffffff;
    font-size: 29rpx;
    font-weight: 400;
    color: #000000;
    line-height: 104rpx;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20.83rpx;

    text {
      margin-left: 47.22rpx;
    }

    .right {
      width: 14rpx;
      height: 21rpx;
      margin-right: 47.22rpx;
    }
  }
}
</style>
